package c03.thread.api.run;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

@Slf4j(topic = "c.FutureTaskDemo")
public class FutureTaskTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer> task = new FutureTask<>(() -> {
            log.debug("running");
            Thread.sleep(2000);
            return 100;
        });

        Thread t = new Thread(task, "t1");
        t.start();
        Integer r = task.get();// 等待task返回结果（2s后）
        log.debug("{}", r);
    }
}
